home *** CD-ROM | disk | FTP | other *** search
/ Electro GIG / Electro GIG.iso / gig / tutor.ins < prev    next >
Text File  |  1995-07-24  |  3KB  |  138 lines

  1. #!/bin/csh -f 
  2. #
  3. #
  4. # -c do not cd to home directory
  5. # -n do -not rewind, extract next file
  6. # -f specify filename for tar command
  7. #
  8.  
  9. # make sure path contains necessary directories
  10. set path = (/usr/bsd /usr/ucb /bin /usr/bin /etc /usr/etc $path)
  11. rehash 
  12.  
  13. # check if user is root
  14. set id_line = `id | fgrep 'root'`
  15. if (! $status) then
  16.   echo do not run this script as root
  17.   exit 1
  18. endif
  19.  
  20. set do_not_rewind=0
  21. set do_cd_home=1
  22. set position = 2    # default position is after second tapemarker
  23.  
  24. # which machine is this script running on
  25. set MACHINE = `uname -m`
  26. switch ($MACHINE)
  27.   case IP[0-9]:
  28.   case IP[0-9][0-9]:
  29.   case IP[0-9][0-9][0-9]:
  30.     set machine = 'iris'
  31.     breaksw;
  32.   case 'sun':
  33.   case 'sun4':
  34.   case 'sun4[a-z0-9]':
  35.     set machine = 'sun4'
  36.     breaksw;
  37.   case 9000/7[0-9][0-9]:
  38.     set machine = 'hp'
  39.     breaksw;
  40.   case 'MIPS':
  41.   case 'RISC':
  42.     set machine = 'dec'
  43.     breaksw;
  44.   default:
  45.     set probl_no = 2
  46.     goto problem
  47. endsw
  48.  
  49. set nr_tape = ""
  50. set cd_file = "$0"
  51. set cd_file = $cd_file:r
  52. set cd_file = "$cd_file".tar
  53.  
  54. switch ($machine)
  55.   case 'iris'
  56.     set nr_tape = "/dev/nrtape"
  57.     breaksw;
  58.   case 'sun4':
  59.     set nr_tape = "/dev/nrst0"
  60.     breaksw;
  61.   case 'hp':
  62.     set nr_tape = "/dev/rmt/0mn"    
  63.     breaksw;
  64.   case 'dec':
  65.     set nr_tape = "/dev/nrmt0h"
  66.     breaksw;
  67.   default:
  68.     set probl_no = 2
  69.     goto problem
  70. endsw
  71.  
  72. if ( -e $cd_file ) then
  73.   set nr_tape = $cd_file
  74. endif
  75.  
  76. # command line parsing
  77.   set arguments = `getopt cnp:f: $*`
  78.   if ( $status != 0 ) then
  79.     echo "usage: tutor.ins [-f filename]"
  80.     exit 2
  81.   endif
  82.   foreach i ( $arguments )
  83.     switch ( $i ) 
  84.       case '-c':
  85.         set do_cd_home = 0 
  86.         breaksw
  87.       case '-n':
  88.         set do_not_rewind = 1 
  89.         breaksw
  90.       case '-p':
  91.         set position = $arguments[2]
  92.         shift arguments
  93.         breaksw
  94.       case '-f':
  95.         set nr_tape=$arguments[2]
  96.         shift arguments
  97.         breaksw
  98.       case '--':
  99.        break
  100.     endsw
  101.     shift arguments
  102.   end
  103.  
  104.  
  105. set MT = "mt -t $nr_tape"
  106.  
  107. if ( -f $nr_tape ) then # check wether nrtape is a normal file
  108.   set do_not_rewind = 2 
  109. endif
  110.  
  111. if ( $do_cd_home) then
  112.   cd $HOME
  113. endif
  114.  
  115. if ($do_not_rewind == 0) then
  116.   $MT rewind
  117.   $MT fsf $position
  118. endif
  119. if (($do_not_rewind == 1) && ($machine == dec)) then
  120.   # skip tapemarker 
  121.   $MT fsf 1
  122. endif
  123. #echo extracting tutorial from $nr_tape cwd: $cwd
  124.  
  125. tar xovf $nr_tape
  126.  
  127. if ($do_not_rewind == 0) then
  128.   $MT rewind
  129. endif
  130.  
  131. exit 0;
  132.  
  133. problem:
  134.    echo problem nr $probl_no
  135.  
  136. exit $probl_no
  137. #-----------------------------
  138.